package com.burstly.lib.component.networkcomponent.burstly.html.ormma;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.URLUtil;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.VideoView;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.NoSeekMediaController;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer;
import com.burstly.lib.component.networkcomponent.burstly.html.IRichMediaAdListener;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.util.OrmmaPlayer;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.util.OrmmaPlayerListener;
import com.burstly.lib.component.networkcomponent.burstly.wrapper.WebViewClientWrapper;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.UiSafeWebView;
import com.burstly.lib.util.Utils;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;

public class OrmmaView extends UiSafeWebView
  implements ViewTreeObserver.OnGlobalLayoutListener, IActivityLifeCycleAware, View.OnTouchListener
{
  public static final String ACTION_KEY = "action";
  private static final String AD_DATA = "AD_DATA";
  private static final int[] ATTRS = { 16843039, 16843040 };
  private static final int BACKGROUND_ID = 101;
  public static final String DIMENSIONS = "expand_dimensions";
  private static final String ERROR_ACTION = "action";
  private static final String ERROR_MESSAGE = "message";
  private static final String EXPAND_PROPERTIES = "expand_properties";
  public static final String EXPAND_URL = "expand_url";
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final int MESSAGE_CLOSE = 1001;
  private static final int MESSAGE_EXPAND = 1004;
  private static final int MESSAGE_HIDE = 1002;
  private static final int MESSAGE_OPEN = 1006;
  private static final int MESSAGE_PLAY_AUDIO = 1008;
  private static final int MESSAGE_PLAY_VIDEO = 1007;
  private static final int MESSAGE_RAISE_ERROR = 1009;
  private static final int MESSAGE_RESIZE = 1000;
  public static final int MESSAGE_SHOW = 1003;
  public static final int ORMMA_ID = 102;
  private static final int PLACEHOLDER_ID = 100;
  public static final String PLAYER_PROPERTIES = "player_properties";
  private static final String RESIZE_HEIGHT = "resize_height";
  private static final String RESIZE_WIDTH = "resize_width";
  private static final String TAG = "OrmmaView";
  public static final String VERSION = "1.1";
  static boolean sHtmlVideoIsPlaying;
  private static OrmmaPlayer sPlayer;
  private int mContentViewHeight;
  private int mDefaultHeight;
  private int mDefaultWidth;
  private float mDensity;
  private GestureDetector mGestureDetector;
  private boolean mGotLayoutParams;
  final Handler mHandler = new Handler()
  {
    public void handleMessage(Message paramAnonymousMessage)
    {
      Bundle localBundle = paramAnonymousMessage.getData();
      switch (paramAnonymousMessage.what)
      {
      case 1005:
      default:
      case 1000:
      case 1001:
      case 1002:
      case 1003:
      case 1004:
      case 1006:
      case 1008:
      case 1007:
      case 1009:
      }
      while (true)
      {
        super.handleMessage(paramAnonymousMessage);
        return;
        OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_RESIZE event.", new Object[0]);
        OrmmaView.access$602(OrmmaView.this, OrmmaView.ViewState.RESIZED);
        ViewGroup.LayoutParams localLayoutParams = OrmmaView.this.getLayoutParams();
        localLayoutParams.height = localBundle.getInt("resize_height", localLayoutParams.height);
        localLayoutParams.width = localBundle.getInt("resize_width", localLayoutParams.width);
        String str4 = "window.ormmaview.fireChangeEvent({ state: 'resized', size: { width: " + localLayoutParams.width + ", height: " + localLayoutParams.height + "}});";
        OrmmaView.this.injectJavaScript(str4);
        OrmmaView.this.requestLayout();
        if (OrmmaView.this.mListener != null)
        {
          OrmmaView.this.mListener.onResize();
          continue;
          OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_CLOSE event.", new Object[0]);
          switch (OrmmaView.7.$SwitchMap$com$burstly$lib$component$networkcomponent$burstly$html$ormma$OrmmaView$ViewState[OrmmaView.this.mViewState.ordinal()])
          {
          default:
            break;
          case 1:
            OrmmaView.this.closeResized();
            break;
          case 2:
            OrmmaView.this.closeExpanded();
            break;
          case 3:
            OverlayContainer localOverlayContainer = OrmmaView.this.getHostingOverlay();
            if ((OrmmaView.this.mPlacementType.equals("interstitial")) && (localOverlayContainer != null))
            {
              localOverlayContainer.hideOverlayed();
              continue;
              if (OrmmaView.this.mViewState == OrmmaView.ViewState.EXPANDED)
                OrmmaView.this.closeExpanded();
              OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_HIDE event.", new Object[0]);
              OrmmaView.this.setVisibility(8);
              OrmmaView.access$602(OrmmaView.this, OrmmaView.ViewState.HIDDEN);
              OrmmaView.this.injectJavaScript("window.ormmaview.fireChangeEvent({ state: 'hidden' });");
              if (OrmmaView.this.mListener != null)
              {
                OrmmaView.this.mListener.onHide();
                continue;
                OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_SHOW event.", new Object[0]);
                OrmmaView.access$602(OrmmaView.this, OrmmaView.ViewState.DEFAULT);
                OrmmaView.this.injectJavaScript("window.ormmaview.fireChangeEvent({ state: 'default' });");
                OrmmaView.this.setVisibility(0);
                if (OrmmaView.this.mListener != null)
                {
                  OrmmaView.this.mListener.onShow();
                  continue;
                  OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_EXPAND event.", new Object[0]);
                  OrmmaView.this.doExpand(localBundle);
                  continue;
                  OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_OPEN event.", new Object[0]);
                  OrmmaView.access$602(OrmmaView.this, OrmmaView.ViewState.LEFT_BEHIND);
                  continue;
                  OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_PLAY_AUDIO event.", new Object[0]);
                  OrmmaView.this.playAudioImpl(localBundle);
                  continue;
                  OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_PLAY_VIDEO event.", new Object[0]);
                  OrmmaView.this.playVideoImpl(localBundle);
                  continue;
                  OrmmaView.LOG.logDebug("OrmmaView", "Handling MESSAGE_RAISE_ERROR event.", new Object[0]);
                  String str1 = localBundle.getString("message");
                  String str2 = localBundle.getString("action");
                  String str3 = "window.ormmaview.fireErrorEvent(\"" + str1 + "\", \"" + str2 + "\")";
                  OrmmaView.this.injectJavaScript(str3);
                }
              }
            }
            break;
          }
        }
      }
    }
  };
  private String mHtmlData;
  volatile boolean mHtmlReady;
  private int mIndex;
  private int mInitLayoutHeight;
  private int mInitLayoutWidth;
  volatile boolean mInitialized;
  private boolean mKeyboardOut;
  private IRichMediaAdListener mListener;
  private String mPlacementType = "inline";
  private final HashSet<String> mRegisteredProtocols = new HashSet();
  private TimeOut mTimeOut;
  private OrmmaUtilityController mUtilityController;
  private ViewState mViewState = ViewState.DEFAULT;
  final WebViewClient mWebViewClient = new WebViewClient()
  {
    public void onLoadResource(WebView paramAnonymousWebView, String paramAnonymousString)
    {
      OrmmaView.LOG.logDebug("OrmmaView", "lr:{0}", new Object[] { paramAnonymousString });
    }

    public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString)
    {
      OrmmaView.this.mHtmlReady = true;
      OrmmaView.access$102(OrmmaView.this, (int)(OrmmaView.this.getHeight() / OrmmaView.this.mDensity));
      OrmmaView.access$302(OrmmaView.this, (int)(OrmmaView.this.getWidth() / OrmmaView.this.mDensity));
      OrmmaView.this.fireReadyEvent();
    }

    public void onReceivedError(WebView paramAnonymousWebView, int paramAnonymousInt, String paramAnonymousString1, String paramAnonymousString2)
    {
      OrmmaView.LOG.logDebug("OrmmaView", "error:{0}", new Object[] { paramAnonymousString1 });
      super.onReceivedError(paramAnonymousWebView, paramAnonymousInt, paramAnonymousString1, paramAnonymousString2);
    }

    public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
    {
      Uri localUri = Uri.parse(paramAnonymousString);
      try
      {
        if ((OrmmaView.this.mListener != null) && (OrmmaView.this.isRegisteredProtocol(localUri)))
        {
          OrmmaView.this.mListener.handleRequest(paramAnonymousString);
          return true;
        }
        if (paramAnonymousString.startsWith("tel:"))
        {
          Intent localIntent2 = new Intent("android.intent.action.DIAL", Uri.parse(paramAnonymousString));
          localIntent2.addFlags(268435456);
          OrmmaView.this.getContext().startActivity(localIntent2);
          return true;
        }
      }
      catch (Exception localException1)
      {
        OrmmaView.LOG.logThrowable("OrmmaView", localException1);
        try
        {
          Intent localIntent1 = new Intent();
          localIntent1.setAction("android.intent.action.VIEW");
          localIntent1.setData(localUri);
          localIntent1.addFlags(268435456);
          OrmmaView.this.getContext().startActivity(localIntent1);
          return true;
        }
        catch (Exception localException2)
        {
          OrmmaView.LOG.logThrowable("OrmmaView", localException2);
          return false;
        }
        if (paramAnonymousString.startsWith("mailto:"))
        {
          Intent localIntent3 = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString));
          localIntent3.addFlags(268435456);
          OrmmaView.this.getContext().startActivity(localIntent3);
          return true;
        }
        Intent localIntent4 = new Intent();
        localIntent4.setAction("android.intent.action.VIEW");
        localIntent4.setData(localUri);
        localIntent4.addFlags(268435456);
        OrmmaView.this.getContext().startActivity(localIntent4);
      }
      return true;
    }
  };

  public OrmmaView(Context paramContext)
  {
    super(paramContext);
    initialize();
  }

  public OrmmaView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext);
    initialize();
    TypedArray localTypedArray = getContext().obtainStyledAttributes(paramAttributeSet, ATTRS);
    int i = localTypedArray.getDimensionPixelSize(0, -1);
    int j = localTypedArray.getDimensionPixelSize(1, -1);
    if ((i > 0) && (j > 0))
      this.mUtilityController.setMaxSize(i, j);
    localTypedArray.recycle();
  }

  public OrmmaView(Context paramContext, IRichMediaAdListener paramIRichMediaAdListener)
  {
    super(paramContext);
    setListener(paramIRichMediaAdListener);
    initialize();
  }

  private FrameLayout changeContentArea(OrmmaController.Dimensions paramDimensions)
  {
    FrameLayout localFrameLayout1 = (FrameLayout)getRootView().findViewById(16908290);
    if (localFrameLayout1 == null)
      return null;
    disableFocusForChildren(localFrameLayout1);
    setFocusableInTouchMode(true);
    View localView = (View)getParent();
    ViewGroup localViewGroup = (ViewGroup)localView.getParent();
    int i = localViewGroup.getChildCount();
    for (int j = 0; ; j++)
      if ((j >= i) || (localViewGroup.getChildAt(j) == localView))
      {
        this.mIndex = j;
        FrameLayout localFrameLayout2 = new FrameLayout(getContext());
        localFrameLayout2.setId(100);
        ViewGroup.LayoutParams localLayoutParams = new ViewGroup.LayoutParams(getWidth(), getHeight());
        localViewGroup.removeView(localView);
        localViewGroup.addView(localFrameLayout2, j, localLayoutParams);
        FrameLayout localFrameLayout3 = new FrameLayout(getContext());
        localFrameLayout3.setId(101);
        localFrameLayout3.setPadding(paramDimensions.x, paramDimensions.y, 0, 0);
        localFrameLayout3.setOnTouchListener(new View.OnTouchListener()
        {
          public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
          {
            OrmmaView.LOG.logInfo("OrmmaView", "Background touch called.", new Object[0]);
            return true;
          }
        });
        FrameLayout.LayoutParams localLayoutParams1 = createLayoutParams(paramDimensions);
        localFrameLayout3.addView(localView, localLayoutParams1);
        localFrameLayout1.addView(localFrameLayout3, localLayoutParams1);
        return localFrameLayout3;
      }
  }

  private static void changeFocusable(ViewGroup paramViewGroup, boolean paramBoolean)
  {
    int i = paramViewGroup.getChildCount();
    int j = 0;
    if (j < i)
    {
      View localView = paramViewGroup.getChildAt(j);
      int k;
      if ((localView instanceof ViewGroup))
      {
        ViewGroup localViewGroup = (ViewGroup)localView;
        if (paramBoolean)
        {
          k = 131072;
          label43: localViewGroup.setDescendantFocusability(k);
        }
      }
      while (true)
      {
        j++;
        break;
        k = 393216;
        break label43;
        localView.setFocusable(paramBoolean);
      }
    }
  }

  private void closeResized()
  {
    if (this.mListener != null)
      this.mListener.onResizeClose();
    String str = "window.ormmaview.fireChangeEvent({ state: 'default', size: { width: " + this.mDefaultWidth + ", " + "height: " + this.mDefaultHeight + "}" + "});";
    LOG.logDebug("OrmmaView", "closeResized: injection: {0}", new Object[] { str });
    injectJavaScript(str);
    resetLayout();
  }

  private FrameLayout.LayoutParams createLayoutParams(OrmmaController.Dimensions paramDimensions)
  {
    int i = Utils.getFillparentValue();
    FrameLayout.LayoutParams localLayoutParams1 = new FrameLayout.LayoutParams(i, i);
    FrameLayout.LayoutParams localLayoutParams2 = new FrameLayout.LayoutParams(paramDimensions.width, paramDimensions.height);
    localLayoutParams2.topMargin = paramDimensions.x;
    localLayoutParams2.leftMargin = paramDimensions.y;
    setLayoutParams(localLayoutParams2);
    return localLayoutParams1;
  }

  private static void disableFocusForChildren(ViewGroup paramViewGroup)
  {
    changeFocusable(paramViewGroup, false);
  }

  private void doExpand(Bundle paramBundle)
  {
    OrmmaController.Dimensions localDimensions;
    OrmmaController.Properties localProperties;
    FrameLayout localFrameLayout;
    if (this.mViewState != ViewState.EXPANDED)
    {
      localDimensions = (OrmmaController.Dimensions)paramBundle.getParcelable("expand_dimensions");
      String str1 = paramBundle.getString("expand_url");
      localProperties = (OrmmaController.Properties)paramBundle.getParcelable("expand_properties");
      if (URLUtil.isValidUrl(str1))
        loadUrl(str1);
      localFrameLayout = changeContentArea(localDimensions);
      if (localFrameLayout != null);
    }
    else
    {
      return;
    }
    setCustomBackground(localProperties, localFrameLayout);
    setCustomCloseButton(localProperties, localFrameLayout);
    String str2 = "window.ormmaview.fireChangeEvent({ state: 'expanded', size: { width: " + (int)(localDimensions.width / this.mDensity) + ", height: " + (int)(localDimensions.height / this.mDensity) + "} });";
    LOG.logDebug("OrmmaView", "doExpand: injection: {0}", new Object[] { str2 });
    injectJavaScript(str2);
    requestFocus(130);
    if (this.mListener != null)
      this.mListener.onExpand();
    this.mViewState = ViewState.EXPANDED;
  }

  private static void enableFocusForChildren(ViewGroup paramViewGroup)
  {
    changeFocusable(paramViewGroup, true);
  }

  private int getContentViewHeight()
  {
    View localView = getRootView().findViewById(16908290);
    if (localView != null)
      return localView.getHeight();
    return -1;
  }

  static OrmmaPlayer getPlayer(Context paramContext)
  {
    try
    {
      if (sPlayer != null)
        sPlayer.releasePlayer();
      sPlayer = new OrmmaPlayer(paramContext);
      OrmmaPlayer localOrmmaPlayer = sPlayer;
      return localOrmmaPlayer;
    }
    finally
    {
    }
  }

  @TargetApi(11)
  private void initialize()
  {
    if (Build.VERSION.SDK_INT >= 11)
      setLayerType(1, null);
    setScrollContainer(false);
    setVerticalScrollBarEnabled(false);
    setHorizontalScrollBarEnabled(false);
    requestFocus(130);
    setOnTouchListener(this);
    this.mGestureDetector = new GestureDetector(new ScrollEater());
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    Context localContext = getContext();
    ((WindowManager)localContext.getSystemService("window")).getDefaultDisplay().getMetrics(localDisplayMetrics);
    this.mDensity = localDisplayMetrics.density;
    getSettings().setJavaScriptEnabled(true);
    getSettings().setPluginsEnabled(true);
    this.mUtilityController = new OrmmaUtilityController(this, localContext);
    addJavascriptInterface(this.mUtilityController, "ORMMAUtilityControllerBridge");
    setWebViewClient(new WebViewClient());
    this.mContentViewHeight = getContentViewHeight();
    getViewTreeObserver().addOnGlobalLayoutListener(this);
    if (Build.VERSION.SDK_INT >= 7)
      setWebChromeClient(new WebChromeClient(null));
  }

  private boolean isRegisteredProtocol(Uri paramUri)
  {
    String str = paramUri.getScheme();
    if (str == null);
    Iterator localIterator;
    do
      while (!localIterator.hasNext())
      {
        return false;
        localIterator = this.mRegisteredProtocols.iterator();
      }
    while (!((String)localIterator.next()).equalsIgnoreCase(str));
    return true;
  }

  private void reset()
  {
    if (this.mViewState == ViewState.EXPANDED)
      closeExpanded();
    while (true)
    {
      invalidate();
      this.mUtilityController.deleteOldAds();
      this.mUtilityController.stopAllListeners();
      resetLayout();
      return;
      if (this.mViewState == ViewState.RESIZED)
        closeResized();
    }
  }

  private void resetLayout()
  {
    ViewGroup.LayoutParams localLayoutParams = getLayoutParams();
    if (this.mGotLayoutParams)
    {
      localLayoutParams.height = this.mInitLayoutHeight;
      localLayoutParams.width = this.mInitLayoutWidth;
    }
    setVisibility(0);
    requestLayout();
  }

  private void setCustomBackground(OrmmaController.Properties paramProperties, FrameLayout paramFrameLayout)
  {
    if (paramProperties.useBackground)
      paramFrameLayout.setBackgroundColor(paramProperties.backgroundColor | 268435456 * (int)(255.0F * paramProperties.backgroundOpacity));
  }

  private void setCustomCloseButton(OrmmaController.Properties paramProperties, FrameLayout paramFrameLayout)
  {
    if (paramProperties.useCusomClose)
    {
      Button localButton = new Button(getContext());
      localButton.setText("Close ad");
      paramFrameLayout.addView(localButton, new FrameLayout.LayoutParams(Utils.getFillparentValue(), (int)(60.0F * this.mDensity)));
      localButton.setOnClickListener(new View.OnClickListener()
      {
        @SuppressLint({"HandlerLeak"})
        public void onClick(View paramAnonymousView)
        {
          OrmmaView.this.mHandler.sendEmptyMessage(1001);
        }
      });
    }
  }

  public void addJavascriptObject(Object paramObject, String paramString)
  {
    addJavascriptInterface(paramObject, paramString);
  }

  public void clearView()
  {
    reset();
    super.clearView();
  }

  public void close()
  {
    this.mHandler.sendEmptyMessage(1001);
  }

  protected void closeExpanded()
  {
    try
    {
      resetContents();
      String str = "window.ormmaview.fireChangeEvent({ state: 'default', size: { width: " + this.mDefaultWidth + ", height: " + this.mDefaultHeight + "}});";
      LOG.logDebug("OrmmaView", "closeExpanded: injection: {0}", new Object[] { str });
      injectJavaScript(str);
      this.mViewState = ViewState.DEFAULT;
      setVisibility(0);
      if (this.mListener != null)
        this.mListener.onExpandClose();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  protected void closeOpened(View paramView)
  {
    ((ViewGroup)((Activity)getContext()).getWindow().getDecorView()).removeView(paramView);
    requestLayout();
  }

  public void deregisterProtocol(String paramString)
  {
    if (paramString != null)
      this.mRegisteredProtocols.remove(paramString.toLowerCase());
  }

  public void expand(OrmmaController.Dimensions paramDimensions, String paramString, OrmmaController.Properties paramProperties)
  {
    Message localMessage = this.mHandler.obtainMessage(1004);
    Bundle localBundle = new Bundle();
    localBundle.putParcelable("expand_dimensions", paramDimensions);
    localBundle.putString("expand_url", paramString);
    localBundle.putParcelable("expand_properties", paramProperties);
    localMessage.setData(localBundle);
    this.mHandler.sendMessage(localMessage);
  }

  void fireReadyEvent()
  {
    if ((isShown()) && (!this.mInitialized) && (this.mHtmlReady))
    {
      this.mUtilityController.init(this.mDensity);
      this.mInitialized = true;
    }
  }

  public ConnectivityManager getConnectivityManager()
  {
    return (ConnectivityManager)getContext().getSystemService("connectivity");
  }

  public Handler getJsHandler()
  {
    return this.mHandler;
  }

  public String getPlacementType()
  {
    return this.mPlacementType;
  }

  public String getSize()
  {
    return "{ width: " + (int)(getWidth() / this.mDensity) + ", " + "height: " + (int)(getHeight() / this.mDensity) + "}";
  }

  @JavascriptInterface
  public String getState()
  {
    return this.mViewState.toString().toLowerCase();
  }

  public void hide()
  {
    this.mHandler.sendEmptyMessage(1002);
  }

  public void injectJavaScript(String paramString)
  {
    if ((!wasDestroyed()) && (paramString != null) && (paramString.length() > 0))
      loadUrl("javascript:" + paramString);
  }

  @JavascriptInterface
  public boolean isExpanded()
  {
    return this.mViewState == ViewState.EXPANDED;
  }

  public void loadDataWithBaseURL(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5)
  {
    this.mInitialized = false;
    this.mHtmlReady = false;
    reset();
    if (this.mTimeOut != null)
      this.mTimeOut.cancel();
    this.mTimeOut = new TimeOut();
    this.mHtmlData = this.mUtilityController.prepareWrappedContentString(paramString2, "mraid=ormma;");
    new Timer().schedule(this.mTimeOut, 2000L, 2000L);
    super.loadDataWithBaseURL("", this.mHtmlData, paramString3, paramString4, paramString5);
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    if (!this.mGotLayoutParams)
    {
      ViewGroup.LayoutParams localLayoutParams = getLayoutParams();
      this.mInitLayoutHeight = localLayoutParams.height;
      this.mInitLayoutWidth = localLayoutParams.width;
      this.mGotLayoutParams = true;
    }
    fireReadyEvent();
  }

  public void onDestroy(Activity paramActivity)
  {
    if (!wasDestroyed())
    {
      super.onDestroy(paramActivity);
      stopLoading();
      destroy();
    }
  }

  protected void onDetachedFromWindow()
  {
    this.mUtilityController.stopAllListeners();
    super.onDetachedFromWindow();
  }

  public void onGlobalLayout()
  {
    boolean bool = this.mKeyboardOut;
    if ((!this.mKeyboardOut) && (this.mContentViewHeight >= 0) && (getContentViewHeight() >= 0) && (this.mContentViewHeight != getContentViewHeight()))
    {
      bool = true;
      injectJavaScript("window.ormmaview.fireChangeEvent({ keyboardState: true});");
    }
    if ((this.mKeyboardOut) && (this.mContentViewHeight >= 0) && (getContentViewHeight() >= 0) && (this.mContentViewHeight == getContentViewHeight()))
    {
      bool = false;
      injectJavaScript("window.ormmaview.fireChangeEvent({ keyboardState: false});");
    }
    if (this.mContentViewHeight < 0)
      this.mContentViewHeight = getContentViewHeight();
    this.mKeyboardOut = bool;
  }

  public boolean onKey(Activity paramActivity, int paramInt, KeyEvent paramKeyEvent)
  {
    return false;
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    switch (paramMotionEvent.getAction())
    {
    default:
    case 0:
    case 1:
    }
    while (true)
    {
      return false;
      if (!paramView.hasFocus())
        paramView.requestFocus();
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    if (this.mGestureDetector.onTouchEvent(paramMotionEvent))
      paramMotionEvent.setAction(3);
    return super.onTouchEvent(paramMotionEvent);
  }

  void onViewableChanged(int paramInt)
  {
    StringBuilder localStringBuilder;
    if (this.mInitialized)
    {
      localStringBuilder = new StringBuilder().append("window.ormmaview.fireViewableChangedEvent(");
      if (paramInt != 0)
        break label46;
    }
    label46: for (boolean bool = true; ; bool = false)
    {
      injectJavaScript(bool + ");");
      return;
    }
  }

  @TargetApi(8)
  protected void onVisibilityChanged(View paramView, int paramInt)
  {
    fireReadyEvent();
    onViewableChanged(paramInt);
    super.onVisibilityChanged(paramView, paramInt);
  }

  public void open(String paramString, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
  {
    if (this.mListener != null)
    {
      this.mListener.onClick(paramString);
      return;
    }
    Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramString));
    LOG.logDebug("OrmmaView", "open: {0}", new Object[] { paramString });
    localIntent.addFlags(268435456);
    getContext().startActivity(localIntent);
  }

  public void playAudio(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, String paramString2, String paramString3)
  {
    OrmmaController.PlayerProperties localPlayerProperties = new OrmmaController.PlayerProperties();
    localPlayerProperties.setProperties(false, paramBoolean1, paramBoolean2, paramBoolean4, paramBoolean3, paramString2, paramString3);
    Bundle localBundle = new Bundle();
    localBundle.putString("action", ACTION.PLAY_AUDIO.toString());
    localBundle.putString("expand_url", paramString1);
    localBundle.putParcelable("player_properties", localPlayerProperties);
    if (localPlayerProperties.isFullScreen())
      try
      {
        Intent localIntent = new Intent(getContext(), OrmmaActionHandler.class);
        localIntent.putExtras(localBundle);
        getContext().startActivity(localIntent);
        return;
      }
      catch (ActivityNotFoundException localActivityNotFoundException)
      {
        LOG.logThrowable("OrmmaView", localActivityNotFoundException);
        return;
      }
    Message localMessage = this.mHandler.obtainMessage(1008);
    localMessage.setData(localBundle);
    this.mHandler.sendMessage(localMessage);
  }

  public void playAudioImpl(Bundle paramBundle)
  {
    OrmmaController.PlayerProperties localPlayerProperties = (OrmmaController.PlayerProperties)paramBundle.getParcelable("player_properties");
    String str = paramBundle.getString("expand_url");
    OrmmaPlayer localOrmmaPlayer = getPlayer(getContext());
    localOrmmaPlayer.setPlayData(localPlayerProperties, str);
    localOrmmaPlayer.setLayoutParams(new ViewGroup.LayoutParams(1, 1));
    ((ViewGroup)getParent()).addView(localOrmmaPlayer);
    localOrmmaPlayer.playAudio();
  }

  public void playVideo(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, OrmmaController.Dimensions paramDimensions, String paramString2, String paramString3)
  {
    Message localMessage = this.mHandler.obtainMessage(1007);
    OrmmaController.PlayerProperties localPlayerProperties = new OrmmaController.PlayerProperties();
    localPlayerProperties.setProperties(paramBoolean1, paramBoolean2, paramBoolean3, false, paramBoolean4, paramString2, paramString3);
    Bundle localBundle = new Bundle();
    localBundle.putString("expand_url", paramString1);
    localBundle.putString("action", ACTION.PLAY_VIDEO.toString());
    localBundle.putParcelable("player_properties", localPlayerProperties);
    if (paramDimensions != null)
      localBundle.putParcelable("expand_dimensions", paramDimensions);
    if (localPlayerProperties.isFullScreen());
    while (paramDimensions == null)
      try
      {
        Intent localIntent = new Intent(getContext(), OrmmaActionHandler.class);
        localIntent.putExtras(localBundle);
        getContext().startActivity(localIntent);
        return;
      }
      catch (ActivityNotFoundException localActivityNotFoundException)
      {
        LOG.logThrowable("OrmmaView", localActivityNotFoundException);
        return;
      }
    localMessage.setData(localBundle);
    this.mHandler.sendMessage(localMessage);
  }

  public void playVideoImpl(Bundle paramBundle)
  {
    OrmmaController.PlayerProperties localPlayerProperties = (OrmmaController.PlayerProperties)paramBundle.getParcelable("player_properties");
    OrmmaController.Dimensions localDimensions = (OrmmaController.Dimensions)paramBundle.getParcelable("expand_dimensions");
    String str = paramBundle.getString("expand_url");
    OrmmaPlayer localOrmmaPlayer = getPlayer(getContext());
    localOrmmaPlayer.setPlayData(localPlayerProperties, str);
    FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(localDimensions.width, localDimensions.height);
    localLayoutParams.topMargin = localDimensions.x;
    localLayoutParams.leftMargin = localDimensions.y;
    localOrmmaPlayer.setLayoutParams(localLayoutParams);
    FrameLayout localFrameLayout1 = new FrameLayout(getContext());
    localFrameLayout1.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
      {
        OrmmaView.LOG.logInfo("OrmmaView", "Background touch called.", new Object[0]);
        return true;
      }
    });
    localFrameLayout1.setId(101);
    localFrameLayout1.setPadding(localDimensions.x, localDimensions.y, 0, 0);
    FrameLayout localFrameLayout2 = (FrameLayout)getRootView().findViewById(16908290);
    int i = Utils.getFillparentValue();
    localFrameLayout2.addView(localFrameLayout1, new FrameLayout.LayoutParams(i, i));
    localFrameLayout1.addView(localOrmmaPlayer);
    setVisibility(4);
    localOrmmaPlayer.setListener(new OrmmaPlayerListener()
    {
      public void onComplete()
      {
        FrameLayout localFrameLayout = (FrameLayout)OrmmaView.this.getRootView().findViewById(101);
        ((ViewGroup)localFrameLayout.getParent()).removeView(localFrameLayout);
        OrmmaView.this.setVisibility(0);
      }

      public void onError()
      {
        onComplete();
      }

      public void onPrepared()
      {
      }
    });
    localOrmmaPlayer.playVideo();
  }

  public void raiseError(String paramString1, String paramString2)
  {
    Message localMessage = this.mHandler.obtainMessage(1009);
    Bundle localBundle = new Bundle();
    localBundle.putString("message", paramString1);
    localBundle.putString("action", paramString2);
    localMessage.setData(localBundle);
    this.mHandler.sendMessage(localMessage);
  }

  @JavascriptInterface
  public void registerProtocol(String paramString)
  {
    if (paramString != null)
      this.mRegisteredProtocols.add(paramString.toLowerCase());
  }

  public void resetContents()
  {
    FrameLayout localFrameLayout1 = (FrameLayout)getRootView();
    FrameLayout localFrameLayout2 = (FrameLayout)localFrameLayout1.findViewById(16908290);
    if (localFrameLayout2 == null);
    FrameLayout localFrameLayout3;
    ViewGroup localViewGroup1;
    do
    {
      return;
      enableFocusForChildren(localFrameLayout2);
      localFrameLayout3 = (FrameLayout)localFrameLayout1.findViewById(100);
      FrameLayout localFrameLayout4 = (FrameLayout)localFrameLayout1.findViewById(101);
      localViewGroup1 = (ViewGroup)getParent();
      localFrameLayout4.removeView(localViewGroup1);
      ViewGroup localViewGroup2 = (ViewGroup)localViewGroup1.getParent();
      if (localViewGroup2 != null)
        localViewGroup2.removeView(localViewGroup1);
      localFrameLayout2.removeView(localFrameLayout4);
      resetLayout();
    }
    while (localFrameLayout3 == null);
    ViewGroup localViewGroup3 = (ViewGroup)localFrameLayout3.getParent();
    localViewGroup3.addView(localViewGroup1, this.mIndex);
    localViewGroup3.removeView(localFrameLayout3);
  }

  public void resize(int paramInt1, int paramInt2)
  {
    Message localMessage = this.mHandler.obtainMessage(1000);
    Bundle localBundle = new Bundle();
    localBundle.putInt("resize_width", paramInt1);
    localBundle.putInt("resize_height", paramInt2);
    localMessage.setData(localBundle);
    this.mHandler.sendMessage(localMessage);
  }

  public WebBackForwardList restoreState(Bundle paramBundle)
  {
    this.mHtmlData = paramBundle.getString("AD_DATA");
    super.loadDataWithBaseURL(null, this.mHtmlData, "text/html", "utf-8", null);
    return null;
  }

  public WebBackForwardList saveState(Bundle paramBundle)
  {
    paramBundle.putString("AD_DATA", this.mHtmlData);
    return null;
  }

  public void setInterstitial(boolean paramBoolean)
  {
    super.setInterstitial(paramBoolean);
    if (paramBoolean);
    for (String str = "interstitial"; ; str = "inline")
    {
      this.mPlacementType = str;
      return;
    }
  }

  public void setListener(IRichMediaAdListener paramIRichMediaAdListener)
  {
    this.mListener = paramIRichMediaAdListener;
  }

  @JavascriptInterface
  public void setMaxSize(int paramInt1, int paramInt2)
  {
    this.mUtilityController.setMaxSize(paramInt1, paramInt2);
  }

  public void setWebViewClient(WebViewClient paramWebViewClient)
  {
    super.setWebViewClient(new WebViewWrapper(paramWebViewClient, this.mWebViewClient));
  }

  public void show()
  {
    this.mHandler.sendEmptyMessage(1003);
  }

  public static enum ACTION
  {
    static
    {
      ACTION[] arrayOfACTION = new ACTION[2];
      arrayOfACTION[0] = PLAY_AUDIO;
      arrayOfACTION[1] = PLAY_VIDEO;
    }
  }

  static class ScrollEater extends GestureDetector.SimpleOnGestureListener
  {
  }

  class TimeOut extends TimerTask
  {
    int mCount = 0;
    int mProgress = 0;

    TimeOut()
    {
    }

    public void run()
    {
      OrmmaView.this.mHandler.post(new Runnable()
      {
        public void run()
        {
          int i = OrmmaView.this.getProgress();
          if (i == 100)
            OrmmaView.TimeOut.this.cancel();
          while (true)
          {
            OrmmaView.TimeOut.this.mProgress = i;
            return;
            if (OrmmaView.TimeOut.this.mProgress != i)
              continue;
            OrmmaView.TimeOut localTimeOut = OrmmaView.TimeOut.this;
            localTimeOut.mCount = (1 + localTimeOut.mCount);
            if (OrmmaView.TimeOut.this.mCount != 3)
              continue;
            try
            {
              OrmmaView.this.stopLoading();
              OrmmaView.TimeOut.this.cancel();
            }
            catch (Exception localException)
            {
              while (true)
              {
                OrmmaView.LOG.logWarning("OrmmaView", "error in stopLoading", new Object[0]);
                OrmmaView.LOG.logThrowable("OrmmaView", localException);
              }
            }
          }
        }
      });
    }
  }

  private static enum ViewState
  {
    static
    {
      EXPANDED = new ViewState("EXPANDED", 2);
      HIDDEN = new ViewState("HIDDEN", 3);
      LEFT_BEHIND = new ViewState("LEFT_BEHIND", 4);
      OPENED = new ViewState("OPENED", 5);
      ViewState[] arrayOfViewState = new ViewState[6];
      arrayOfViewState[0] = DEFAULT;
      arrayOfViewState[1] = RESIZED;
      arrayOfViewState[2] = EXPANDED;
      arrayOfViewState[3] = HIDDEN;
      arrayOfViewState[4] = LEFT_BEHIND;
      arrayOfViewState[5] = OPENED;
    }
  }

  private class WebChromeClient extends WebChromeClient
  {
    private WebChromeClient.CustomViewCallback mCallback;
    private FrameLayout mContentView;
    View mVideoFrameLayout;
    private View mVideoProgressView;
    VideoView mVideoView;

    private WebChromeClient()
    {
    }

    private VideoView getVideoView(View paramView)
    {
      if ((paramView instanceof FrameLayout))
      {
        View localView = ((FrameLayout)paramView).getFocusedChild();
        if ((localView != null) && ((localView instanceof VideoView)))
          return (VideoView)localView;
      }
      return null;
    }

    public View getVideoLoadingProgressView()
    {
      if (this.mVideoProgressView == null)
      {
        Context localContext = OrmmaView.this.getContext();
        LinearLayout localLinearLayout = new LinearLayout(localContext);
        localLinearLayout.setOrientation(1);
        localLinearLayout.setLayoutParams(new FrameLayout.LayoutParams(-2, -2, 17));
        ProgressBar localProgressBar = new ProgressBar(localContext, null, 16842874);
        localProgressBar.setLayoutParams(new FrameLayout.LayoutParams(-2, -2, 17));
        localLinearLayout.addView(localProgressBar);
        localProgressBar.willNotCacheDrawing();
        this.mVideoProgressView = localLinearLayout;
      }
      return this.mVideoProgressView;
    }

    public void onHideCustomView()
    {
      if (OrmmaView.sHtmlVideoIsPlaying)
      {
        OrmmaView.sHtmlVideoIsPlaying = false;
        OrmmaView.this.setVisibility(0);
        this.mContentView.removeView(this.mVideoFrameLayout);
        this.mCallback.onCustomViewHidden();
        OrmmaView.LOG.logDebug("OrmmaView", "Video hidden", new Object[0]);
      }
    }

    public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
    {
      OrmmaView.sHtmlVideoIsPlaying = true;
      if (this.mContentView == null)
        this.mContentView = ((FrameLayout)OrmmaView.this.getRootView().findViewById(16908290));
      this.mVideoFrameLayout = paramView;
      this.mVideoView = getVideoView(this.mVideoFrameLayout);
      if (this.mVideoView != null)
        this.mVideoView.setMediaController(new NoSeekMediaController(OrmmaView.this.getContext()));
      OrmmaView.this.setVisibility(8);
      int i = Utils.getFillparentValue();
      this.mContentView.addView(paramView, new FrameLayout.LayoutParams(i, i, 17));
      this.mCallback = paramCustomViewCallback;
    }
  }

  private static class WebViewWrapper extends WebViewClientWrapper
  {
    private final WebViewClient mOrmmaClient;

    public WebViewWrapper(WebViewClient paramWebViewClient1, WebViewClient paramWebViewClient2)
    {
      super();
      this.mOrmmaClient = paramWebViewClient2;
    }

    public void onLoadResource(WebView paramWebView, String paramString)
    {
      super.onLoadResource(paramWebView, paramString);
      this.mOrmmaClient.onLoadResource(paramWebView, paramString);
    }

    public void onPageFinished(WebView paramWebView, String paramString)
    {
      super.onPageFinished(paramWebView, paramString);
      this.mOrmmaClient.onPageFinished(paramWebView, paramString);
    }

    public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2)
    {
      super.onReceivedError(paramWebView, paramInt, paramString1, paramString2);
      this.mOrmmaClient.onReceivedError(paramWebView, paramInt, paramString1, paramString2);
    }

    public boolean shouldOverrideUrlLoading(WebView paramWebView, String paramString)
    {
      return (super.shouldOverrideUrlLoading(paramWebView, paramString)) || (this.mOrmmaClient.shouldOverrideUrlLoading(paramWebView, paramString));
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaView
 * JD-Core Version:    0.6.2
 */